﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using System.Web.Security;

namespace He.Web.user
{
    public partial class reg_activate : System.Web.UI.Page
    {
        public Model.member member;
        public int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = InputUtil.Get("uid", 0);
            string reset_key = InputUtil.Get("rid");
            member = new BLL.member().GetModel(id);
            if (member == null)
            {
                Response.Redirect("~/error.aspx?s=用户不存在");
            }
            else
            {
                DateTime expire = new DateTime();
                if (DateTime.TryParse(member.reset_expires, out expire))
                {
                    if (DateTime.Compare(DateTime.Now, expire) < 0)
                    {
                        if (member.reset_key != reset_key)
                        {
                            Response.Redirect("~/error.aspx?s=无效链接");
                        }
                        else
                        {
                            member.status = (int)Enums.MemberStatus.正常;
                            member.reset_key = "";
                            member.reset_expires = "";
                            new BLL.member().Update(member);
                            FormsAuthentication.SetAuthCookie(member.user_name, false);
                            Response.Redirect("/user/reg_success.aspx");
                        }
                    }
                    else
                    {
                        Response.Redirect("~/error.aspx?s=该链接已过期，请重新发送邮件");
                    }
                }
                else
                {
                    Response.Redirect("~/error.aspx?s=无效链接");
                }
            }
        }
    }
}